﻿@*<div class="page-quote">
    <blockquote class="layui-elem-quote">修改密码</blockquote>
</div>*@


<form class="layui-form">
    <div class="layui-tab-content page-detail">
        <div class="layui-tab-item layui-show">
            <input type="hidden" id="hidId" value="" />
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">原密码<span class="required">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" id="tbOldPassword" name="tbOldPassword" required lay-verify="required|maxLength20" placeholder="" autocomplete="off" class="layui-input" value="">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">新密码<span class="required">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" id="tbNewPassword" name="tbNewPassword" required lay-verify="required|maxLength20" placeholder="" autocomplete="off" class="layui-input" value="">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">确认密码<span class="required">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" id="tbRepeatPassword" name="tbRepeatPassword" required lay-verify="required|maxLength20" placeholder="" autocomplete="off" class="layui-input" value="">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row detail-submit">
                <div class="layui-layer-btn layui-layer-btn-c">
                    <a class="layui-layer-btn0" id="btnSave">修改</a>
                </div>
            </div>
        </div>
    </div>
</form>

<script>
    var PersonUpdatePwd = function () {
        let inited = false;
        let data = {};

        function initData() {
            layui.use(['form', 'layer'], function () {
                var form = layui.form;
                form.verify({
                    maxLength20: [/^.{0,20}$/, '长度最大为20']
                });
            });
        }

        return {
            init() {//初始化
                if (!inited) {
                    initData();
                    inited = true;
                }
            },
            //修改密码
            updatePwd() {
                var oldPassword = $("#tbOldPassword").val();
                var newPassword = $("#tbNewPassword").val();
                var repeatPassword = $("#tbRepeatPassword").val();

                //开启loading
                layer = layui.layer;
                var index = layer.load(2);
                $.ajax({
                    url: "/Person/UpdatePassword",
                    type: "post",
                    data: { oldPassword: oldPassword, newPassword: newPassword, repeatPassword: repeatPassword },
                    success: function (data) {
                        layer.close(index)
                        if (data.state == 1) {
                            parent.layer.msg("修改成功", { shade: 0.1, icon: 1 }, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                        } else if (data.state == 0) {
                            parent.layer.open({
                                title: '提示'
                                , content: "修改失败 " + data.msg
                                , shade: 0.4
                                , icon: 5
                            });
                        } else {
                            parent.layer.open({
                                title: '提示'
                                , content: "修改异常 " + data.msg
                                , shade: 0.4
                                , icon: 2
                            });
                        }
                    }
                });
            },
            //取消
            cancel() {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        };
    }();
    UserAddOrUpdate.init();
</script>
